import { Card, message, Spin, Table } from "antd";
import { connect } from "dva";
import { routerRedux } from "dva/router";
import moment from "moment";
import PropTypes from "prop-types";
import * as R from "ramda";
import React, { PureComponent } from "react";
import PateoAuthButtons from "@/common/PateoAuthButtons/PateoAuthButtons";
import PateoSearchFormExpand from "@/common/PateoTable/PateoSearchForm/PateoSearchFormExpand";
import Ellipsis from "@/components/Ellipsis";
import { translate } from "@/utils/activity";
import * as G from "@/utils/common";
import styles from "./index.less";
import SendMsgModal from "./sendMsgModal";
import MsgRulerModal from "../creditCar/msgRulerModal";
import { Form } from '@ant-design/compatible';
import { getDicByKey, getDictOptionsByCode } from '@/support/common';
import enums from "../creditCar/enums";
import RiskLogModal from "../creditCar/riskLogModal";
import PateoSearchForm from '../../../components/common/PateoSearchForm';

@connect((state) => ({
  menu: state.menu,
  warningRecord: state.warningRecord,
}))
@Form.create()
export default class WarningRecord extends PureComponent {
  static contextTypes = {
    authButton: PropTypes.array,
    dicData: PropTypes.any,
  };

  state = {
    formValues: {},
    sendMsgModalVisible: false,
    selectedRecord: {},
    userList: [],
    tboxRouseloading: false,
    tboxRouseCount: 35,

    ruleList: [],
    msgRuleModalVisible: false,
    ruleListSelectedRecord: {},
    ruleListType: 1,
    businessId: "",
    creditTypeOptions: [],
    orgList: [],
    abnormalList: [],
    riskLogModalVisible:false,//风控日志
  };

  handlemsgRemove = (record) => {
    const { dispatch } = this.props;
    let params = {
      businessCode: "risk-warn-log",
      vin: record.vin,
      businessId: record.uuid,
    };

    dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/ivi/warn/remove",
        ...params,
      },
      callback: (response) => {
        if (response.statusCode === "0") {
          message.success("修改成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  handleWarnMsg = (record) => {
    let params = {
      businessCode: "risk-warn-log",
      vin: record.vin,
      iviNoticeUuid: "",
      businessId: record.uuid,
    };
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/ivi/warn",
        ...params,
      },
      callback: (response) => {
        if (response.statusCode === "0") {
          message.success("发送成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  handlemsgRulerList = (record, type) => {
    let params = {};
    if (type == 1) {
      // 正常行驶
      if (record.riskStatus == "0") {
        params = {
          showTypes: [1, 2, 3],
          useType: 3,
        };
      } else if (record.riskStatus == "1") {
        params = {
          showTypes: [1, 2, 3],
          useType: 2,
        };
      } else if (record.riskStatus == "2") {
        params = {
          showTypes: [1, 2, 3],
          useType: 1,
        };
      } else {
        params = {
          showTypes: [1, 2, 3],
          useType: 3,
        };
      }
    } else if (type == 2) {
      //锁车
      params = {
        showTypes: [1, 2, 3],
        useType: 2,
      };
    } else if (type == 3) {
      params = {
        showTypes: [1, 2, 3],
        useType: 1,
      };
    }
    params.businessId = record.uuid;
    this.props.dispatch({
      type: "warningRecord/postObjWithRes",
      payload: {
        url: "/mscreditbusiness/iviNotice/list",
        ...params,
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          this.setState({
            ruleList: response.data,
            msgRuleModalVisible: true,
            ruleListSelectedRecord: record,
            ruleListType: type,
            businessId: record.uuid,
          });
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  getDic = () =>{
    const {menu: { dicData }} = this.props;
    const typeOption = getDictOptionsByCode(dicData, 'creditType');
    this.setState({
      creditTypeOptions: typeOption.map(e => ({
            label: e.label,
            value: e.value,
          })),
   })
  }
  loop = (arr) => {
    let tree= JSON.parse(JSON.stringify(arr))
      let newData = []
    const expanded = datas => {
      if (datas&& datas.length > 0){
        datas.forEach(e => {
          newData.push({sid: e.sid, name: e.orgName});
          expanded(e.children);
        })
      }
    };
    expanded(tree);
    return newData;
  }
  handleGetOrgList = () => {
    this.props.dispatch({
      type: "warningRecord/getDataWithRes",
      payload: {
        url: "/org/tree",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          if (response.data && response.data.length > 0) {
            const newData =  this.loop(response.data)
            this.setState({
              orgList: newData,
            });
          }
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  handleGetriskEventList = () => {
    this.props.dispatch({
      type: "warningRecord/postObjWithRes",
      payload: {
        url: "/mscreditbusiness/event/page", 
        ...{
          curPage: 1,
          pageSize: 1000,
          enable: enums.riskEventEnable.effective.value,
        },
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          this.setState({
            abnormalList: response.data?.rows,
          });
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  componentDidMount() {
    const { dispatch } = this.props;
    this.getDic();
    this.handleGetOrgList();
    this.handleGetriskEventList();
    this.queryRecordList();
  }

  componentWillUnmount() {
    clearInterval(this.timer2);
    clearInterval(this.timer);
  }
  queryRecordList = () => {
    const { dispatch } = this.props;
    const { formValues } = this.state;
    const params = {
        curPage: 1,
        pageSize: 10,
        ...formValues,
    }
    dispatch({
      type: "warningRecord/queryRecordList",
      payload: {
        url: '/mscreditbusiness/vehicle/risk/warn/record/page',
        ...params,
      },
    });
  };
  handleRangePicker = (fields) => {
    if (G.isNotEmptyAndNil(fields["riskTriggerDate"])) {
      const [start, end] = fields.riskTriggerDate;
      fields["riskTriggerDateStart"] = moment(start).format(
        "YYYY-MM-DD HH:mm:ss"
      );
      fields["riskTriggerDateEnd"] = moment(end).format("YYYY-MM-DD HH:mm:ss");
    } else {
      fields["riskTriggerDateStart"] = null;
      fields["riskTriggerDateEnd"] = null;
    }
    delete fields["riskTriggerDate"];
  };
  //点击详情
  handleDetail = (record) => {
    sessionStorage.setItem("warningRecord", JSON.stringify(record));
    sessionStorage.setItem("typeOption", JSON.stringify(this.state.creditTypeOptions));
    sessionStorage.setItem(
      "warningRecordBackPath",
      "/creditPlatform/warningRecord"
    );
    this.props.dispatch(
      routerRedux.push({
        pathname:
          "/creditPlatform/warningRecordDetail",
      })
    );
  };
  handleRelieve = (vin, warnStatus, record) => {
    // if (warnStatus == 1) {
    //   let params = {
    //     businessCode: "risk-warn-log",
    //     vin: vin,
    //     businessId: record.uuid,
    //   };
    //   this.props.dispatch({
    //     type: "warningRecord/postDataWithRes",
    //     payload: {
    //       url: "/mscreditbusiness/vehicle/ivi/warn/remove",
    //       ...params,
    //     },
    //     callback: (response) => {
    //       if (response && response.statusCode == "0") {
    //         message.success("解除车机告警成功");
    //         this.props.dispatch({
    //           type: "warningRecord/postDataWithRes",
    //           payload: {
    //            url: "/mscreditbusiness/vehicle/risk/warn/remove",
    //             vin: record.vin,
    //             businessId: record.uuid,
    //             businessCode: "risk-warn-log",
    //           },
    //           callback: (response) => {
    //             if (response && response.statusCode == "0") {
    //               message.success("已解除预警");
    //               this.queryRecordList();
    //             } else {
    //               // message.error(response.statusMessage);
    //             }
    //           },
    //         });
    //         this.queryRecordList();
    //       } else {
    //         // message.error(response.statusMessage);
    //       }
    //     },
    //   });
    // } else {
      this.props.dispatch({
        type: "warningRecord/postDataWithRes",
        payload: {
         url: "/mscreditbusiness/vehicle/risk/warn/remove",
          vin: record.vin,
          businessId: record.uuid,
          businessCode: "risk-warn-log",
        },
        callback: (response) => {
          if (response && response.statusCode == "0") {
            message.success("已解除预警");
            this.queryRecordList();
          } else {
            // message.error(response.statusMessage);
          }
        },
      });
    // }
  };
  handleMark = (record) => {
    const { dispatch } = this.props;
    const param = {
      uuid: record.uuid,
      businessId: record.uuid,
      // businessCode: "risk-warn-log",
    }
    dispatch({
      type: 'warningRecord/postDataWithRes',
      payload: { url: '/mscreditbusiness/vehicle/risk/warn/deal', ...param},
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("操作成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  handleDealWarning = (record) => {
    const { dispatch } = this.props;
    const orgId = record.orgId;
    dispatch({
      type: 'warningRecord/getDataWithRes',
      payload: {
        url: '/org/accountInfo/list',
        orgId,
      },
      callback: (response) => {
        this.setState({
          userList: response.data,
          sendMsgModalVisible: true,
          selectedRecord: record,
        });
      },
    });
  };
  handleLocation = (record) => {
    sessionStorage.setItem("vin", record?.vin);
    sessionStorage.setItem("warningRecordUuuid", record?.uuid);
    sessionStorage.setItem("businessCode", "risk-warn-log");
    sessionStorage.setItem(
      "warningCarLocationbackPath",
      "/creditPlatform/warningRecord"
    );
    this.props.dispatch(
      routerRedux.push({
        pathname:
          "/creditPlatform/warningCarLocation",
      })
    );
  };

  handleLockCar = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/lock/set",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("设置锁车成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };

  handleUnlockCar = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/lock/remove",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("解除锁车成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  /**
   * 解除跛行并锁车
   * @param {} vin
   */
  handleUnlimpAndLockCar = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/limp/remove",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          // message.success("解除跛行成功");
          this.props.dispatch({
            type: "warningRecord/postDataWithRes",
            payload: {
              url: "/mscreditbusiness/vehicle/lock/set",
              vin: record.vin,
              businessId: record.uuid,
              businessCode: "risk-warn-log",
            },
            callback: (response) => {
              if (response && response.statusCode == "0") {
                message.success("解除跛行并锁车成功");
                this.queryRecordList();
              } else {
                // message.error(response.statusMessage);
              }
            },
          });
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };

  handleLimp = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/limp/set",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("设置跛行成功");
          this.queryRecordList();
        } else {
          message.error(response.statusMessage);
        }
      },
    });
  };
  /**
   * 解除锁车并跛行
   * @param {} vin
   */
  handleUnlockAndLimp = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/lock/remove",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          // message.success("解除跛行成功");
          this.props.dispatch({
            type: "warningRecord/postDataWithRes",
            payload: {
              url: "/mscreditbusiness/vehicle/limp/set",
              vin: record.vin,
              businessId: record.uuid,
              businessCode: "risk-warn-log",
            },
            callback: (response) => {
              if (response && response.statusCode == "0") {
                message.success("解除锁车并跛行成功");
                this.queryRecordList();
              } else {
                // message.error(response.statusMessage);
              }
            },
          });
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };

  handleUnlimp = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/limp/remove",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("解除跛行成功");
          this.queryRecordList();
        } else {
          // message.error(response.statusMessage);
        }
      },
    });
  };
  /**
   * tbox唤醒
   * @param {data} record
   */
  handleWakeUp = (record) => {
    this.props.dispatch({
      type: "warningRecord/postDataWithRes",
      payload: {
        url: "/mscreditbusiness/vehicle/tbox/wake",
        vin: record.vin,
        businessId: record.uuid,
        businessCode: "risk-warn-log",
      },
      callback: (response) => {
        if (response && response.statusCode == "0") {
          message.success("已经给该车辆发送远程唤醒指令");
          this.setState({
            tboxRouseloading: true,
          });
          let tboxRouseCount = 35;
          let tboxRouseSearchCount = 3;
          this.timer = setInterval(() => {
            tboxRouseCount--;
            this.setState({ tboxRouseCount });
            //请求详情接口
            if (tboxRouseCount <= 0) {
              this.setState({
                tboxRouseloading: false,
                tboxRouseCount: 35,
              });
              clearInterval(this.timer);
              message.error("TBOX没有被成功唤醒");
            }
          }, 1000);
          const uuid = record.uuid;
          this.timer2 = setInterval(() => {
            tboxRouseSearchCount--;
            //请求详情接口
            this.props.dispatch({
              type: "warningRecord/recordDetail",
              payload: {
                url: '/mscreditbusiness/vehicle/tbox/wake/result',
                vin: record.vin,
              },
              callback: (response) => {
                if (response && response.statusCode == "0") {
                  console.log("请求接口详情", tboxRouseSearchCount);
                  //比较TBOX失联天数
                  if (response.data) {
                    message.success("TBOX被成功唤醒");
                    this.queryRecordList();
                    clearInterval(this.timer2);
                    clearInterval(this.timer);
                    this.setState({
                      tboxRouseloading: false,
                      tboxRouseCount: 35,
                    });
                  }
                } else {
                  message.error(response.statusMessage);
                }
              },
            });

            if (tboxRouseSearchCount <= 0 || tboxRouseCount <= 0) {
              clearInterval(this.timer2);
            }
          }, 10000);
        } else {
          message.error(response.statusMessage);
        }
      },
      // callback: (response) => {
      //   if (response && response.statusCode == "0") {
      //     message.success(response.statusMessage)
      //     this.queryRecordList()
      //   } else {
      //     message.error(response.statusMessage)
      //   }
      // },
    });
  };

  handleTableChange = (page) => {
    const { dispatch } = this.props;
    const { formValues } = this.state;
    const params = {
      curPage: page.current,
      pageSize: page.pageSize,
      ...formValues,
    };
    dispatch({
      type: "warningRecord/queryRecordList",
      payload: {
        url: '/mscreditbusiness/vehicle/risk/warn/record/page',
        ...params,
      },
    });
  };
  showBtn = (record, type) => {
    const { limpEnable, riskStatus, riskWarnStatus, dealStatus, tboxLostDays } =
      record;

    switch (type) {
      case "location": {
        return !(
          (riskStatus == "0" && riskWarnStatus == 1 && dealStatus == 1) ||
          (riskStatus == "1" && riskWarnStatus == 1 && dealStatus == 1) ||
          (limpEnable == 1 &&
            riskStatus == "2" &&
            riskWarnStatus == 1 &&
            dealStatus == 1) ||
          (limpEnable == 1 && riskStatus == "2" && riskWarnStatus == 0) ||
          (riskStatus == "1" && riskWarnStatus == 0) ||
          (riskStatus == "0" && riskWarnStatus == 0)
        );
      }
      case "relieve": {
        return !(
          (limpEnable == 1 && riskStatus == "2" && riskWarnStatus == 0) ||
          (riskStatus == "1" && riskWarnStatus == 0) ||
          (riskStatus == "0" && riskWarnStatus == 0)
        );
      }
      case "mark": {
        return !(
          (riskStatus == "0" && riskWarnStatus == 1 && dealStatus == 1) ||
          (riskStatus == "1" && riskWarnStatus == 1 && dealStatus == 1) ||
          (limpEnable == 1 && riskStatus == "2" && dealStatus == 1) ||
          (riskStatus == "1" && riskWarnStatus == 0 && dealStatus == 1) ||
          (riskStatus == "0" && riskWarnStatus == 0)
        );
      }
      case "dealWarning": {
        return !(
          (riskStatus == "0" && riskWarnStatus == 1 && dealStatus == 1) ||
          (riskStatus == "1" && riskWarnStatus == 1 && dealStatus == 1) ||
          (limpEnable == 1 &&
            riskStatus == "2" &&
            riskWarnStatus == 1 &&
            dealStatus == 1) ||
          (limpEnable == 1 && riskStatus == "2" && riskWarnStatus == 0) ||
          (riskStatus == "1" && riskWarnStatus == 0) ||
          (riskStatus == "0" && riskWarnStatus == 0)
        );
      }
      case "lockCar": {
        return (
          (limpEnable == 1 &&
            riskStatus == "0" &&
            riskWarnStatus == 1 &&
            dealStatus == 0) ||
          (limpEnable != 1 &&
            riskStatus == "0" &&
            riskWarnStatus == 1 &&
            dealStatus == 0)
        );
      }
      case "unlimpAndLockCar": {
        return (
          limpEnable == 1 &&
          riskStatus == "2" &&
          riskWarnStatus == 1 &&
          dealStatus == 0
        );
      }
      case "unlockCar": {
        return (
          (limpEnable == 1 && riskStatus == "1" && riskWarnStatus == 1) ||
          (limpEnable != 1 &&
            riskStatus == "1" &&
            riskWarnStatus == 1 &&
            dealStatus == 1) ||
          (riskStatus == "1" && riskWarnStatus == 0) ||
          (limpEnable != 1 &&
            riskStatus == "1" &&
            riskWarnStatus == 1 &&
            dealStatus == 0)
        );
      }
      case "limp": {
        return (
          limpEnable == 1 &&
          riskStatus == "0" &&
          riskWarnStatus == 1 &&
          dealStatus == 0
        );
      }
      case "unlockAndLimp": {
        return (
          limpEnable == 1 &&
          riskStatus == "1" &&
          riskWarnStatus == 1 &&
          dealStatus == 0
        );
      }
      case "unlimp": {
        return limpEnable == 1 && riskStatus == "2";
      }
      case "wakeUp": {
        return tboxLostDays > 0;
      }
      default:
        return false;
    }
  };
  //风控日志
  changeriskLogModalVisible = (flag) => {
    if (flag) {
      this.setState({
        riskLogModalVisible: false,
      });
    } else {
      this.setState({
        riskLogModalVisible: false,
      });
    }
  };
  handleRiskLog=(record)=>{
    this.setState({
      riskvin: record.vin,
      riskLogModalVisible: true,
    })
  }
  /**
   * 参数校验
   * @param fieldsValue
   */
  dataFormat = (fields) => {
    if (G.isNotEmptyAndNil(fields['riskTriggerDate'])) {
      const [start, end] = fields.riskTriggerDate;
      fields['riskTriggerDateStart'] = moment(start).format('YYYY-MM-DD HH:mm:ss');
      fields['riskTriggerDateEnd'] = moment(end).format('YYYY-MM-DD HH:mm:ss');
      delete fields['riskTriggerDate'];
    }
    return fields;
  };
     //行车轨迹
     handleTrack = (record) => {
      sessionStorage.setItem("warning_track_vin", record.vin);
      const { formValues, pageObj } = this.state;
      this.props.dispatch(
        routerRedux.push({
          pathname: "/creditPlatform/warningRecordTrack",
          state: { pageObj, formValues },
        })
      );
    }
  render() {
    const {
     warningRecord: {
        loading,
        recordList,
        pagination,
      },
      dispatch,
    } = this.props;
    const {
      sendMsgModalVisible,
      formValues,
      selectedRecord,
      userList,
      tboxRouseloading,
      tboxRouseCount,
      creditTypeOptions,
      orgList,
      abnormalList,
      riskLogModalVisible
    } = this.state;
    const {menu: { permissions }} = this.props;
    const {location: { pathname }} = this.props;
    const detailBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_detail');
    const relieveBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_relieve');
    const markBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_mark');
    const dealWarningBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_deal');
    const locationBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_location');
    const lockCarBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_lockCar');
    const unlockCarBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_unlockCar');
    const limpBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_limp');
    const unlimpBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_unlimp');
    const wakeUpBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_wakeup');
    const orgOptions = orgList.map((item) => {
      return {
        value: item.sid,
        label: item.name,
      };
    });
    const abnormalEventsOptions = abnormalList?.map((item) => {
      return {
        value: item.uuid,
        label: item.riskEventContent,
      };
    });
    const dealStatusOptions = [
      {
        label: "已处理",
        value: 1,
      },
      {
        label: "未处理",
        value: 0,
      },
    ];
    const riskStatusOptions = [
      {
        label: "正常行驶",
        value: "0",
      },
      {
        label: "锁车",
        value: "1",
      },
      {
        label: "跛行",
        value: "2",
      },
    ];
    const riskWarnStatusOptions = [
      {
        label: "已预警",
        value: 1,
      },
      {
        label: "未预警",
        value: 0,
      },
    ];
    const warnTypeOptions = [
      {
        label: "暂不支持",
        value: 0,
      },
      {
        label: "不可配置",
        value: 1,
      },
      {
        label: "可配置",
        value: 2,
      },
    ];
    const warnStatusOptions = [
      {
        label: "正常",
        value: 0,
      },
      {
        label: "车机告警",
        value: 1,
      },
    ];
    // const limpEnableOptions = [
    //   {
    //     label: '支持',
    //     value: 1
    //   }, {
    //     label: '不支持',
    //     value: 0
    //   }
    // ]
    const searchItems = [
      {
        type: "input",
        title: "VIN号",
        key: "vin",
      },
      {
        type: "select",
        title: "车辆所属公司",
        key: "orgId",
        selectOptions: orgOptions,
      },
      {
        type: "select",
        title: "触发的异常事件",
        key: "riskEventUuid",
        selectOptions: abnormalEventsOptions,
      },
      {
        type: "select",
        title: "处理状态",
        key: "dealStatus",
        selectOptions: dealStatusOptions,
      },
      {
        type: "select",
        title: "授信类型",
        key: "creditType",
        selectOptions: creditTypeOptions,
      },
      {
        type: "rangePicker",
        title: "预警时间",
        key: "riskTriggerDate",
        style: { width: "100%" },
      },
    ];
    const paginationProps = {
      showSizeChanger: true,
      showQuickJumper: true,
      ...pagination,
      showTotal: () => (
        <span>
          共&nbsp;{pagination === undefined ? 0 : pagination.total}&nbsp;条
        </span>
      ),
    };
    const columns = [
      {
        title: "VIN号",
        dataIndex: "vin",
        ellipsis: true,
      },
      {
        title: "车辆所属公司",
        dataIndex: "orgName",
        ellipsis: true,
      },
      {
        title: "车辆风控状态",
        dataIndex: "riskStatus",
        render: translate(R.__, riskStatusOptions),
      },
      {
        title: "预警时间",
        dataIndex: "riskTriggerDate",
        render: (text, record) => moment(text).format("YYYY-MM-DD HH:mm:ss"),
      },
      {
        title: "预警内容",
        dataIndex: "riskWarnMsg",
        render: (text) => (
          <Ellipsis length={15} tooltip>
            {text}
          </Ellipsis>
        ),
      },
      {
        title: "触发的异常事件",
        dataIndex: "riskEventContent",
        render: (text) => (
          <Ellipsis length={15} tooltip>
            {text}
          </Ellipsis>
        ),
      },
      {
        title: "是否支持跛行",
        dataIndex: "limpEnable",
        render: (text) => {
          return text == 1 ? "是" : "否";
        },
      },
      {
        title: "预警状态",
        dataIndex: "riskWarnStatus",
        render: translate(R.__, riskWarnStatusOptions),
      },
      {
        title: "处理状态",
        dataIndex: "dealStatus",
        render: translate(R.__, dealStatusOptions),
      },
      {
        title: "TBOX失联天数",
        dataIndex: "tboxLostDays",
      },
      // {
      //   title: "车机告警类型",
      //   dataIndex: "warnType",
      //   render: translate(R.__, warnTypeOptions),
      // },
      {
        title: "车机告警状态",
        dataIndex: "warnStatus",
        render: translate(R.__, warnStatusOptions),
      },
      {
        title: "授信类型",
        dataIndex: "creditType",
        render: text => {
          if (text == null) {
            return '';
          }
          return getDicByKey(this.context.dicData, `creditType`, text.toString());
        },
      },
      {
        title: "操作",
        dataIndex: "opt",
        fixed: "right",
        align: "center",
        render: (text, record) => {
          console.log('record', record)
          const btns = [];
          const { warnType, warnStatus } = record;
          const warnBtnAuth = permissions.includes(pathname + '/' + 'warningRecord_warn');
          const isWarn =
            warnBtnAuth &&
            warnType != 0 &&
            ((warnType == 1 && record.overduDateCount >= 1) || warnType == 2);
          const detailBtn = {
            title: "详情",
            key: "detailBtn",
            onConfirm: () => this.handleDetail(record),
          };
          let relieveWarnMsg =
            isWarn && warnStatus == 1
              ? "该车目前处于车机告警状态，需要首先解除车机告警状态才能解除预警，是否解除预警?"
              : "是否解除预警?";
          if (record.riskStatus === "1") {
            // 0-正常行驶，1-锁车，2-跛行
            relieveWarnMsg =
              isWarn && warnStatus == 1
                ? "该车目前处于锁车、车机告警状态，需要首先解除锁车、车机告警状态才能解除预警，是否解除预警?"
                : "该车目前处于锁车状态，需要首先解除锁车状态才能解除预警，是否解除预警?";
          } else if (record.riskStatus === "2") {
            relieveWarnMsg =
              isWarn && warnStatus == 1
                ? "该车目前处于跛行、车机告警状态，需要首先解除跛行、车机告警状态才能解除预警，是否解除预警?"
                : "该车目前处于跛行状态，需要首先解除跛行状态才能解除预警，是否解除预警?";
          }
          const relieveBtn = {
            title: "解除预警",
            Popconfirm: true,
            message: relieveWarnMsg,
            key: "relieve",
            onConfirm: () =>
              this.handleRelieve(record.vin, record.warnStatus, record),
          };
          const markBtn = {
            title: "标识为已处理",
            key: "mark",
            onConfirm: () => this.handleMark(record),
          };
          const dealWarningBtn = {
            title: "管理告警",
            key: "dealWarning",
            onConfirm: () => this.handleDealWarning(record),
          };
          const locationBtn = {
            title: "查看定位",
            key: "location",
            onConfirm: () => this.handleLocation(record),
          };
          const limp = {
            title: "跛行",
            Popconfirm: true,
            message:
              isWarn && warnType == 1
                ? "确认要设置跛行和车机告警吗?"
                : "确认跛行",
            key: "limp",
            // onConfirm: () => this.handleLimp(record),
            onConfirm: () =>
              isWarn && warnType != 1
                ? this.handlemsgRulerList(record, 3)
                : this.handleLimp(record),
          };
          const unlockAndLimp = {
            title: "跛行",
            Popconfirm: true,
            message:
              isWarn && warnType == 1
                ? "该车已处于锁车状态，是否解除锁车状态并实施跛行和车机告警吗？"
                : "该车已处于锁车状态，是否解除锁车状态并实施跛行？",
            key: "unlockAndLimp",
            // onConfirm: () => isWarn ? this.handlemsgRulerList(record, 3) : this.handleUnlockAndLimp(record),
            onConfirm: () =>
              isWarn && warnType != 1
                ? this.handlemsgRulerList(record, 3)
                : this.handleLimp(record),
          };
          const lockCarBtn = {
            title: "锁车",
            Popconfirm: true,
            message:
              isWarn && warnType == 1
                ? "确认要设置锁车和车机告警吗?"
                : "确认锁车",
            key: "lockCarBtn",
            onConfirm: () =>
              isWarn && warnType != 1
                ? this.handlemsgRulerList(record, 2)
                : this.handleLockCar(record),
          };

          const unlockCarBtn = {
            title: "解除锁车",
            Popconfirm: true,
            message: "确认解锁车辆",
            key: "unlockCarBtn",
            onConfirm: () => this.handleUnlockCar(record),
          };
          const unlimpAndLockCarBtn = {
            title: "锁车",
            Popconfirm: true,
            message:
              isWarn && warnType == 1
                ? "该车已处于跛行状态，是否解除跛行状态并实施锁车和车机告警吗？"
                : "该车已处于跛行状态，是否解除跛行状态并实施锁车？",
            key: "unlimpAndLockCar",
            onConfirm: () => this.handleUnlimpAndLockCar(record),
          };
          const unlimp = {
            title: "解除跛行",
            Popconfirm: true,
            message: "确认解除跛行",
            key: "unlimp",
            onConfirm: () => this.handleUnlimp(record),
          };
          const wakeUp = {
            title: "TBOX唤醒",
            Popconfirm: true,
            message: "是否要对TBOX进行远程唤醒?",
            key: "wakeUp",
            onConfirm: () => this.handleWakeUp(record),
          };
          const pathBtn = {
            title: "行车轨迹",
            key: "pathBtn",
            onConfirm: () => this.handleTrack(record),
          };
          const riskLogBtn = {//若手动或自动实施锁车/解除锁车/跛行/解除跛行后，则显示风控日志按钮
            title: "风控日志",
            key: "riskLogBtn",
            onConfirm: () => this.handleRiskLog(record),
          };
          btns.push(pathBtn);//行车轨迹
          if(record.riskStatus == 1) btns.push(riskLogBtn);//风控日志
          if (detailBtnAuth) {
            btns.push(detailBtn);
          }
          if (locationBtnAuth && this.showBtn(record, "location")) {
            btns.push(locationBtn);
          }
          if (relieveBtnAuth && this.showBtn(record, "relieve")) {
            btns.push(relieveBtn);
          }
          if (markBtnAuth && this.showBtn(record, "mark")) {
            btns.push(markBtn);
          }
          if (dealWarningBtnAuth && this.showBtn(record, "dealWarning")) {
            btns.push(dealWarningBtn);
          }
          if (lockCarBtnAuth && this.showBtn(record, "lockCar")) {
            btns.push(lockCarBtn);
          }
          if (lockCarBtnAuth && this.showBtn(record, "unlimpAndLockCar")) {
            btns.push(unlimpAndLockCarBtn);
          }
          if (unlockCarBtnAuth && this.showBtn(record, "unlockCar")) {
            btns.push(unlockCarBtn);
          }
          if (limpBtnAuth && this.showBtn(record, "limp")) {
            btns.push(limp);
          }
          if (limpBtnAuth && this.showBtn(record, "unlockAndLimp")) {
            btns.push(unlockAndLimp);
          }
          if (unlimpBtnAuth && this.showBtn(record, "unlimp")) {
            console.log('xxx', this.showBtn(record, "unlimp"))
            btns.push(unlimp);
          }
          if (wakeUpBtnAuth && this.showBtn(record, "wakeUp")) {
            btns.push(wakeUp);
          }
          const msgRulerBtn = {
            title: "车机告警",
            Popconfirm: true,
            message: "是否车机告警",
            key: "msgrulerBtn",
            onConfirm: () =>
              warnType == 1
                ? this.handleWarnMsg(record)
                : this.handlemsgRulerList(record, 1),
          };
          const releaseRulertn = {
            title: "解除车机告警",
            Popconfirm: true,
            message: "是否解除车机告警",
            key: "msgremoverulerBtn",
            onConfirm: () => this.handlemsgRemove(record),
          };
          if (isWarn) {
            if (warnStatus == 0) {
              btns.push(msgRulerBtn);
            } else {
              btns.push(releaseRulertn);
            }
          }
          return (
            <PateoAuthButtons
              authStr="warningRecord"
              btns={btns}
            />
          );
        },
      },
    ];

    return (
      <Spin
        spinning={tboxRouseloading}
        size="large"
        tip={`Loading(${tboxRouseCount})s`}
      >
        <div>
        <Card bordered={false}>
          <PateoSearchForm
            onRef={(val) => (this.searchForm = val)}
            searchItems={searchItems}
            fetchParams={{
              type: 'warningRecord/queryRecordList',
              url: '/mscreditbusiness/vehicle/risk/warn/record/page',
            }}
            saveFormValues={(val) =>
              this.setState({ formValues: Object.assign(formValues, val) })
            }
            handleFormReset={() => this.setState({ formValues: {} })}
            handleFieldsValue={this.dataFormat}
          />
          </Card>
          <Card className={styles.standardTable}>
              <Table
                rowKey={(record) => record.sid}
                columns={columns}
                dataSource={recordList}
                // loading={loading}
                formValues={this.state.formValues}
                pagination={paginationProps}
                onChange={this.handleTableChange}
                scroll={{ x: "max-content" }}
              />
              </Card>
            {/* </div> */}
          {/* </Card> */}
          {sendMsgModalVisible && (
            <SendMsgModal
              changeVisible={() =>
                this.setState({ sendMsgModalVisible: false })
              }
              visible={sendMsgModalVisible}
              userList={userList}
              record={selectedRecord}
              dispatch={dispatch}
              handleSearch={this.queryRecordList}
            />
          )}
          {this.state.msgRuleModalVisible && (
            <MsgRulerModal
              changeVisible={() => {
                this.setState({ msgRuleModalVisible: false });
                // this.queryRecordList();
              }}
              onOk={() => {
                this.setState({ msgRuleModalVisible: false });
                this.queryRecordList();
              }}
              businessCode="risk-warn-log"
              visible={this.state.msgRuleModalVisible}
              ruleList={this.state.ruleList}
              record={this.state.ruleListSelectedRecord}
              dispatch={this.props.dispatch}
              ruleListType={this.state.ruleListType}
              businessId={this.state.businessId}
            />
          )}
          {riskLogModalVisible ? (<RiskLogModal
            changeriskLogModalVisible={this.changeriskLogModalVisible}
            riskvin={this.state.riskvin}
          />) :null}
        </div>
      </Spin>
    );
  }
}
